
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/13 10:30
 */

#include "iostream"
#include "cstring"
#include "algorithm"

using namespace std;

const int m = 20;
const int n = 5;
bool st[m][n];

int main() {
    int p;
    cin >> p;
    int nums[p];
    for (int i = 0; i < p; ++i) {
        cin >> nums[i];
    }

    for (int i = 0; i < p; ++i) {
        int x = nums[i];
        bool flag = false;
        for (int j = 0; j < m; ++j) {
            int k = 0;
            for (; k < n; ++k) {
                if (!st[j][k]) {
                    break;
                }
            }
            if (n - k >= x) {
                for (int l = k; l < k + x; ++l) {
                    st[j][l] = true;
                    cout << n * j + l + 1 << " ";
                }
                cout << endl;
                flag = true;
                break;
            }
        }
        if (!flag) {
            for (int l = 0; l < m * n; ++l) {
                if (x == 0) {
                    break;
                }
                if (!st[l / n][l % n]) {
                    x--;
                    st[l / n][l % n] = true;
                    cout << l + 1 << " ";
                }
            }
            cout << endl;
        }
    }

    return 0;
}